<?php
/**
 * Hesperos library for Zend Framework
 *
 * This script is protected by copyright. It's use, copying, modification
 * and distribution without written consent of the author is prohibited.
 *
 * @category    Hesperos
 * @package     Role
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2011 Krzysztof Kardasz
 * @license     http://www.gnu.org/licenses/lgpl-3.0.txt  GNU Lesser General Public
 * @version     1.0 $Id$
 * @link        http://code.google.com/p/hesperos/
 */

/**
 * Role systemu
 *
 * @category    Hesperos
 * @package     Role
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2011 Krzysztof Kardasz
 * @version     1.0 $Id$
 */
final class Hesperos_Acl_Role
{
    /**
     * Rola administrator główny
     *
     * @var string
     */
    const SUPERADMIN = 'superadmin';

    /**
     * Rola administrator
     *
     * @var string
     */
    const ADMIN = 'admin';

    /**
     * Rola menadżer
     *
     * @var string
     */
    const MANAGER = 'manager';

    /**
     * Rola edytor
     *
     * @var string
     */
    const EDITOR = 'editor';

    /**
     * Rola analityk
     *
     * @var string
     */
    const ANALYST = 'analyst';

    /**
     * Rola użytkownik
     *
     * @var string
     */
    const USER = 'user';

    /**
     * Rola gość
     *
     * @var string
     */
    const ANONYMOUS = 'guest';

    /**
     * Rejestruje dostępne role w obiekcie klasy Zend_Acl
     *
     * @param  Zend_Acl $acl obiekt kontroli dostępu
     * @return Zend_Acl
     */
    public static function register (Zend_Acl $acl)
    {
        $acl
            ->addRole(new Zend_Acl_Role(self::ANONYMOUS))
            ->addRole(new Zend_Acl_Role(self::USER), self::ANONYMOUS)
            ->addRole(new Zend_Acl_Role(self::ANALYST), self::USER)
            ->addRole(new Zend_Acl_Role(self::EDITOR), self::ANALYST)
            ->addRole(new Zend_Acl_Role(self::MANAGER), self::EDITOR)
            ->addRole(new Zend_Acl_Role(self::ADMIN), self::MANAGER)
            ->addRole(new Zend_Acl_Role(self::SUPERADMIN), self::ADMIN);

        return $acl;
    }

    /**
     * Zwraca tablicę dostępnych ról
     *
     * @return array
     */
    public function getAvailableRoles ()
    {
        return array (
            self::SUPERADMIN,
            self::ADMIN,
            self::MANAGER,
            self::EDITOR,
            self::ANALYST,
            self::USER,
            self::ANONYMOUS
        );
    }

    /**
     * Zwraca flagę czy rola jest dostępna
     *
     * @return boolean
     */
    public function isRoleAvailable ($role)
    {
        return in_array($role, $this->getAvailableRoles());
    }
}